<style scoped>
    .role-managment-page {
    }
    .role-managment-page .condition {
        line-height: 36px;
    }
    /*.el-dialog.el-dialog--small{width:37%;}
     #distributiveLegalPerson .el-dialog.el-dialog--small{width:50%;height:500px;}*/
    #distributiveLegalPerson p{display:inline-block;}
    #distributiveLegalPerson .left-title{width:55%;margin-bottom:10px;}
    #distributiveLegalPerson .right-title{width:45%;margin-bottom:10px;}
    #distributiveLegalPerson .el-dialog .el-input{width:100%;}
    #distributiveLegalPerson .my-transfer-box{}

    #distributiveLegalPerson .my-transfer-box .transfer-content{padding:10px;width:40%;height:340px;border:1px solid #ccc;overflow-x:hidden;overflow-y:scroll;}
    #distributiveLegalPerson .my-transfer-box .transfer-transfer .el-checkbox-group{}
    #distributiveLegalPerson .my-transfer-box .transfer-content .el-checkbox-group label{display:block;margin:0 0 10px 0;}

    #distributiveLegalPerson .my-transfer-box .left-transfer{}
    #distributiveLegalPerson .my-transfer-box .left-transfer .el-checkbox-group{}
    #distributiveLegalPerson .my-transfer-box .left-transfer .el-checkbox-group label{}
    #distributiveLegalPerson .my-transfer-box .left-transfer{}

    #distributiveLegalPerson .my-transfer-box .center-transfer{width:12%;margin-top:80px;}
    #distributiveLegalPerson .my-transfer-box .center-transfer .el-button{min-width:48px;display:block;margin:0 auto 10px!important;}

    #distributiveLegalPerson .my-transfer-box .right-transfer{}
    #distributiveLegalPerson .my-transfer-box .right-transfer .el-checkbox-group{}
    #distributiveLegalPerson .my-transfer-box .right-transfer .el-checkbox-group label{}

    /*  修改法人 */
    .el-dialog #companyName .el-form-item__content .el-input{width:100%;}
    .el-dialog #companyName .el-select{width:100%;}
    .el-dialog #companyName .el-select .el-select__tags{overflow-x:hidden;}
    /*重置密码*/
    #company-ul{width:175px;border:1px solid rgb(229, 211, 209);min-height:24px;max-height:100px;overflow-x:hidden;overflow-y:scroll;}
    #company-ul .company-ul-li{padding:0 8px;line-height:24px;}
    #company-ul .company-ul-li:hover{background:#f6f0ee;}
   /* 法人历史记录*/
    #company-ul1{width:175px;border:1px solid rgb(229, 211, 209);min-height:24px;max-height:100px;overflow-x:hidden;overflow-y:scroll;}
    #company-ul1 .company-ul-li1{padding:0 8px;line-height:24px;}
    #company-ul1 .company-ul-li1:hover{background:#f6f0ee;}
</style>

<template>
    <!--  本部人员 -->
    <div class="role-managment-page">
        <el-form :inline="true" :model="queryDepartmentPersonForm" class="demo-form-inline"
                 style="border-bottom:1px solid #ccc;">
            <!--人员名称-->
            <el-form-item :label="nowLangue.personName" class="selectMB10">
                <el-input size="mini" v-model="queryDepartmentPersonForm.name" :placeholder="nowLangue.pleaseImport+nowLangue.personName"></el-input>
            </el-form-item>
            <!--登录账号-->
            <el-form-item :label="nowLangue.loginAccount" class="selectMB10">
                <el-input size="mini" v-model="queryDepartmentPersonForm.code" :placeholder="nowLangue.pleaseImport+nowLangue.loginAccount"></el-input>
            </el-form-item>
            <!--当前状态-->
            <el-form-item :label="nowLangue.currStatus" class="selectMB10">
                <el-select clearable  size="mini" v-model="queryDepartmentPersonForm.enabled" :placeholder="nowLangue.pleaseSelect">
                    <el-option :label="nowLangue.enable" value="true"></el-option>
                    <el-option :label="nowLangue.forbidden" value="false"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item class="selectMB10">
                <!--查询-->
                <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="handleQuery(pageIndex,pageSize)" v-text="nowLangue.query"></el-button>
            </el-form-item>
        </el-form>
        <!--表格-->
        <!--本部人员列表：-->
        <label class="default-label" v-text="nowLangue.ListOfPersonnel"></label>
        <!--分配法人-->
        <el-button class="bolder outsideBtnBS" size="mini" v-if="powerFlag1" type="danger" @click="handleDistributiveLegalPerson()" v-text="nowLangue.distributiveLegalPerson"></el-button>
        <el-table :data="tableData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" width="220" header-align="center" align="center">
                <template scope="scope">
                    <!--分配法人-->
                    <button class="operationItem bolder" v-if="!scope.row.enabled && powerFlag1" @click="handleEdit(scope.$index, scope.row) "v-text="nowLangue.distributiveLegalPerson"></button>
                    <!--分配法人-->
                    <button class="operationItem disabled bolder" v-else-if="scope.row.enabled && powerFlag1" v-text="nowLangue.distributiveLegalPerson"></button>
                    <!--禁用-->
                    <button class="operationItem bolder" v-if="scope.row.enabled && powerFlag1" @click="handleDisable(scope.$index, scope.row)" v-text="nowLangue.forbidden" :disabled="statusDisabled"></button>
                    <!--启用-->
                    <button class="operationItem bolder" v-if="!scope.row.enabled && scope.row.legalPersons && powerFlag1" @click="handleEnable(scope.$index, scope.row)" v-text="nowLangue.enable" :disabled="statusDisabled"></button>
                    <!--重置密码-->
                    <button class="operationItem bolder" v-if="scope.row.enabled && powerFlag2" @click="resetPassword(scope.$index, scope.row)" v-text="nowLangue.resetPassword"></button>
                    <!--重置密码-->
                    <button class="operationItem disabled bolder" v-if="!scope.row.enabled && powerFlag2" v-text="nowLangue.resetPassword"></button>
                    <!--历史记录-->
                    <button class="operationItem bolder" @click="searchHistory(scope.$index, scope.row)" v-text="nowLangue.historicalRecord"></button>
                </template>
            </el-table-column>
            <el-table-column prop="personname" :label="nowLangue.personName" width="130" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="username" :label="nowLangue.loginAccount" width="130" header-align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="enabledText" :label="nowLangue.currStatus" width="80" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <!--所属法人-->
            <el-table-column :label="nowLangue.LegalUnderItsJurisdiction" header-align="center" show-overflow-tooltip>
                <template scope="scope">
                    <template v-for="legalPerson in scope.row.legalPersons"><p>{{legalPerson.legalPersonName}}</p>
                    </template>
                </template>
            </el-table-column>
        </el-table>
        <!--分页-->
        <el-pagination v-if="isPaging" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page="pageIndex" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                       :page-count="totalPage" :total="totalNumber"></el-pagination>
        <!--分配法人 -->
        <!--法人分配人员-->
        <el-dialog id="distributiveLegalPerson" :title="nowLangue.corporateDistributor" :visible.sync="showDistributiveLegalPersonFrom" :lock-scroll="false">
            <el-form :model="legalForm">
                <div class="left-title fleft">
                    <!--法人列表：-->
                    <p class="condition" v-text="nowLangue.listOfLegalPersons"></p>
                    <el-select size="mini" v-model="legalPersonName"  @change="selectLegalPersonName" :placeholder="nowLangue.pleaseSelect">
                        <el-option v-for="(LegalPerson,index) in LegalPersondata" :key="index" :label="LegalPerson.legalPersonName" :value="LegalPerson.legalPersonName" :title="LegalPerson.legalPersonName">
                            <span style="float: left">{{ LegalPerson.legalPersonName }}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">{{ LegalPerson.legalPersonCode }}</span>
                        </el-option>
                    </el-select>
                </div>
                <div class="right-title fleft">
                    <!--待选人员列表：-->
                    <p class="condition" v-text="nowLangue.listOfCandidatesToBeSelected"></p>
                </div>
                <!-- 法人列表 -->
                <div class="my-transfer-box clearfix">
                    <div class="left-transfer transfer-content fleft">
                        <el-checkbox-group v-model="dSleftPersonnel" @change="handleLeftCheckedChange">
                            <el-checkbox v-for="leftPersonnel in leftPersonnelList" :label="leftPersonnel.personName" :key="leftPersonnel.personName">
                                {{leftPersonnel.personName}}
                            </el-checkbox>
                        </el-checkbox-group>
                    </div>
                    <!-- 操作按钮 -->
                    <div class="center-transfer fleft">
                        <el-button size="mini" class="bolder outsideBtnBS" type="danger" @click="toLeftTransfer" > << </el-button>
                        <el-button size="mini" class="bolder outsideBtnBS" type="danger" @click="toRightTransfer" > >> </el-button>
                        <!--清除-->
                        <el-button size="mini" class="bolder outsideBtnBS" type="danger" @click="clearCheckedValue" v-text="nowLangue.eliminate"></el-button>
                        <!--提交-->
                        <el-button size="mini" class="bolder outsideBtnBS" type="danger" @click="submitResult" v-text="nowLangue.submit" :disabled="submitRDisabled"></el-button>
                    </div>
                    <!-- 待选人员列表 -->
                    <div class="right-transfer transfer-content fright" v-if="legalPersonName">
                        <el-checkbox-group v-model="dSrightPersonnel"  @change="handleRightCheckedChange">
                            <el-checkbox size="small" v-for="rightPersonnel in tmpRightPersonnelList" :label="rightPersonnel.personname" :key="rightPersonnel.personname">{{rightPersonnel.personname}}</el-checkbox>
                        </el-checkbox-group>
                    </div>
                    <div class="right-transfer transfer-content fright" v-else>
                        <el-checkbox-group  v-model="dSrightPersonnel"  @change="handleRightCheckedChange">
                            <el-checkbox v-for="rightPersonnel in rightPersonnelList" :label="rightPersonnel.personname" :key="rightPersonnel.personname">{{rightPersonnel.personname}}</el-checkbox>
                        </el-checkbox-group>
                    </div>
                </div>
            </el-form>
        </el-dialog>
        <!--分配法人的弹框-->
        <!--分配法人-->
        <el-dialog :title="nowLangue.distributiveLegalPerson" :visible.sync="dialogFormVisible" size="tiny" :lock-scroll="false">
            <el-form :model="form" ref="form" :inline="true" class="demo-form-inline label-minW100">
                <!--姓    名-->
                <el-form-item :label="nowLangue.fullName">
                    <el-input size="mini" disabled v-model="form.personname" auto-complete="off"></el-input>
                </el-form-item>
                <!--登录账户-->
                <el-form-item :label="nowLangue.loginAccount">
                    <el-input size="mini" 　 disabled v-model="form.username" auto-complete="off"></el-input>
                </el-form-item>
                <!--公司名称-->
                <el-form-item :label="nowLangue.corporateName" id="companyName" class="selectMB10" prop="legalPersonIds" :rules="[{ required: true, message: nowLangue.pleaseSelect}]">
                    <el-select size="mini" v-model="form.legalPersonIds" multiple :placeholder="nowLangue.pleaseSelect"> 
                        <el-option v-for="legalPerson in legalPersonList" :key="legalPerson.id" :label="legalPerson.legalPersonName" :value="legalPerson.id" :title="legalPerson.legalPersonName">
                            <span style="float: left">{{ legalPerson.legalPersonName }}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">{{ legalPerson.legalPersonCode }}</span>
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--返 回-->
                <el-button size="mini" class="bolder outsideBtnBS" @click="dialogFormVisible = false" v-text="nowLangue.return"></el-button>
                <!--保 存-->
                <el-button size="mini" class="bolder outsideBtnBS" type="danger" @click="saveLegalPersonStaff()" v-text="nowLangue.save" :disabled="saveLDisabled"></el-button>
            </div>
        </el-dialog>
        <!--法人历史信息的弹框-->
        <!--历史记录-->
        <el-dialog :title="nowLangue.historicalRecord" :visible.sync="searchHistoryFormVisible" size="tiny" :lock-scroll="false">
            <el-form :model="form" :inline="true" class="demo-form-inline label-minW110">
                <!--姓名-->
                <el-form-item :label="nowLangue.fullName">
                    <el-input size="mini" disabled v-model="form.personname" auto-complete="off"></el-input>
                </el-form-item>
                <!--登录账户-->
                <el-form-item :label="nowLangue.loginAccount">
                    <el-input size="mini" 　 disabled v-model="form.username" auto-complete="off"></el-input>
                </el-form-item>
                <!--历史记录-->
                <el-form-item :label="nowLangue.historicalRecord" class="selectMB10">
                    <ul id="company-ul1">
                        <li class="company-ul-li1" v-for="legalPerson in legalPersonList">{{legalPerson.legalPersonName}}</li>
                    </ul>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--返 回-->
                <el-button size="mini" class="bolder outsideBtnBS" @click="searchHistoryFormVisible = false" v-text="nowLangue.return"></el-button>
            </div>
        </el-dialog>
        <!--重置密码的弹框-->
        <!--重置密码-->
        <el-dialog :title="nowLangue.resetPassword" :visible.sync="resetPasswordFormVisible" size="tiny" :lock-scroll="false">
            <el-form :model="resetPasswordForm" ref="resetPasswordForm"  :inline="true" class="demo-form-inline label-minW110">
                <!--姓名-->
                <el-form-item :label="nowLangue.fullName">
                    <el-input size="mini" disabled v-model="resetPasswordForm.personname" auto-complete="off"></el-input>
                </el-form-item>
                <!--登录账户-->
                <el-form-item :label="nowLangue.loginAccount">
                    <el-input size="mini"  disabled v-model="resetPasswordForm.username" auto-complete="off"></el-input>
                </el-form-item>
                <!--密    码-->
                <el-form-item :label="nowLangue.password" prop="password" :rules="[{ required: true, message: nowLangue.pleaseImport+nowLangue.confirmPassword},{ validator: validatePass, trigger: 'blur' }]">
                    <el-input size="mini" type="password" v-model.trim="resetPasswordForm.password" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.password"></el-input>
                </el-form-item>
                <!--确认密码-->
                <el-form-item :label="nowLangue.confirmPassword" prop="checkPass" :rules="[{ required: true, message: nowLangue.pleaseImport+nowLangue.confirmPassword},{ validator: validatePass2, trigger: 'blur' }]">
                    <el-input size="mini" type="password" v-model.trim="resetPasswordForm.checkPass" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.confirmPassword"></el-input>
                </el-form-item>
                <!-- 新添加的 -->
                <!--公司名称-->
                <el-form-item :label="nowLangue.corporateName" id="company-name" class="selectMB10">
                    <ul id="company-ul">
                        <li class="company-ul-li" v-for="legalPerson in resetPasswordForm.legalPersons">{{legalPerson.legalPersonName}}</li>
                    </ul>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--返 回-->
                <el-button size="mini" class="bolder outsideBtnBS" @click="resetPasswordFormVisible = false" v-text="nowLangue.return"></el-button>
                <!--保 存-->
                <el-button size="mini" class="bolder outsideBtnBS" type="danger" @click="handleSaveResetPassword('resetPasswordForm')" v-text="nowLangue.save" :disabled="saveRPDisabled"></el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
    import Vue from 'vue'
    export default {
        data() {
            var _this=this;
            //重置密码页面中，密码对比验证。
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    var tip1=_this.languageType=="zh"?'请输入密码':'Please input a password';
                    callback(new Error(tip1));
                } else {
                    if (this.resetPasswordForm.checkPass !== '') {
                        this.$refs.resetPasswordForm.validateField('checkPass');
                    }
                    callback();
                }
            };
            var validatePass2 = (rule, value, callback) => {
                if (value === '') {
                    var tip2=_this.languageType=="zh"?'请再次输入密码':'Please enter your password again';
                    callback(new Error(tip2));
                } else if (value !== this.resetPasswordForm.password) {
                    var tip3=_this.languageType=="zh"?'两次输入密码不一致':'The password for the two time is inconsistent';
                    callback(new Error(tip3));
                } else {
                    callback();
                }
            };
            return {
                nowLangue:{},
                validatePass:validatePass,
                validatePass2:validatePass2,
                //分配法人
                //分配法人弹出框
                LegalPersondata: [],  //法人列表
                legalPersonName:"",   //法人列表中的法人名称
                legalPersonCode:"",   //法人列表中的法人code
                legalPersonId:"",   //法人列表中的法人id
                leftPersonnelList:[],      //法人的人员列表
                dSleftPersonnel:[],        // 法人的人员列表默认选中的值
                dSleftPersonnelNameArray:[],  //法人的人员列表中选中后的value数组
                rightPersonnelList: [],    // 人员列表(全部)
                tmpRightPersonnelList: [],  // 向左移之后的人员列表
                dSrightPersonnel:[],     //人员列表中默认选中的值
                dSrightPersonnelNameArray:[],  //人员列表中选中后的value数组


                //查询列表所需要的字段
                queryDepartmentPersonForm: {
                    name: '',
                    code: '',
                    enabled: ''
                },
                //修改本部员工字段
                form: {
                    id: 0,
                    name: '',
                    code: '',
                    password: '',
                    username:'',
                    legalPersonName:'',
                    legalPersonIds: [],
                    legalPersonCode: '',
                    status: false
                },
                //重置密码字段
                resetPasswordForm: {
                    personname: '',
                    username: '',
                    password: '',
                    checkPass: '',
                    legalPersonIds: [],
                    legalPersonCode: '',
                    legalPerson:"",
                    legalPersons:[]
                },
                //分配法人字段
                legalForm:{
                    personname: '',
                    username: '',
                    password: '',
                    legalPersonIds: [],
                    legalPersonCode: ''
                },
                loading:false,
                // 查询列表展示数据时，数据自动注入字段中。
                tableData: [],
                //修改页面中，数据自动注入到修改法人字段。
                legalPersonList: [],

                // 修改法人的弹窗静默状态为关闭
                dialogFormVisible: false,
                searchHistoryFormVisible:false,
                //重置密码弹窗静默状态为关闭
                resetPasswordFormVisible: false,
                //分配法人弹窗静默状态为关闭
                showDistributiveLegalPersonFrom:false,
                //修改弹框中默认当前状态（后期已去掉，但不影响）
                allStatus: 'disable',
                //分页的静默状态
                isPaging: false,
                //当前页（必传）
                pageIndex: 1,
                ////每页多少条
                pageSize: 10,
                //总数量
                totalNumber: 20,
                //总页数
                totalPage: 2,
                //权限
                powerFlag1:false,
                powerFlag2:false,

                selectDisabled:false,//查询禁用
                statusDisabled:false,   //启用禁用操作钮禁用
                submitRDisabled:false,    //分配法人   提交结果操作按钮禁用
                saveLDisabled:false,    //分配法人   保存操作按钮禁用
                saveRPDisabled:false   /// 重置密码  保存操作按钮禁用
            };
        },
        created:function(){
            var _this=this;
            _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
        },
        computed:{
            powerData(){
                return this.$store.state.powerData;
            },
            languageType(){
                return this.$store.state.languageType;
            }
        },
        watch:{
            languageType(){
                var _this=this;
                _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
            },
            powerData(){
                var _this = this;
                for(var i=0;i<_this.powerData.length;i++){
                    if(_this.powerData[i]=="ROLE_security_personnelOfDepartment_distributLegalPerson"){
                        //本部人员分配法人权限
                        _this.powerFlag1=true;
                    }
                    if(_this.powerData[i]=="ROLE_security_personnelOfDepartment_resetPassword"){
                        //本部人员重置密码权限
                        _this.powerFlag2=true;
                    }
                }
            }
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
            //判断权限
            for(var i=0;i<_this.powerData.length;i++){
                if(_this.powerData[i]=="ROLE_security_personnelOfDepartment_distributLegalPerson"){
                    //本部人员分配法人权限
                    _this.powerFlag1=true;
                }
                if(_this.powerData[i]=="ROLE_security_personnelOfDepartment_resetPassword"){
                    //本部人员重置密码权限
                    _this.powerFlag2=true;
                }
            }
            _this.handleQuery(_this.pageIndex, _this.pageSize);
        },

        methods: {

            //分配法人点击事件
            handleDistributiveLegalPerson(){
                var _this = this;
                _this.allPersonnelList();    //待选人员列表
                _this.leftPersonnelList=[];   //左侧人员为空
                // _this.handleQuery(_this.pageIndex, _this.pageSize);
                // _this.dialogFormVisible = false;
                // _this.searchHistoryFormVisible=false,
                // _this.resetPasswordFormVisible = false;
                _this.showDistributiveLegalPersonFrom = true;
                _this.legalForm.legalPersonIds = [];
                var parameters = {
                    pageIndex: 1,
                    enabled:true     //查询出所有启用状态下的法人
                };
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "legalPerson/search",
                    cache: false,
                    data: JSON.stringify(parameters),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.LegalPersondata = data.data.dataList;   //法人列表
                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            //从法人列表中选择法人   下拉菜单
            selectLegalPersonName(){
                var _this=this;
                for(var i=0;i<_this.LegalPersondata.length;i++){
                    if(_this.legalPersonName==_this.LegalPersondata[i].legalPersonName){
                        _this.legalPersonId=_this.LegalPersondata[i].id;
                    }
                }
                _this.selectedPersonnelList();
            },
            //已选法人下面的人员展示
            selectedPersonnelList(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service + "legalPerson/listUsersByEnabledLegalPerson/"+_this.legalPersonId,
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            _this.leftPersonnelList = data.data;   //当前法人下面的人员
                            // 当前法人  可选的人员（右侧的待选人员列表）
                            _this.tmpRightPersonnelList=[];
                            //当前法人下选中的人员
                            var leftTmpName="";
                            for(var i=0;i<_this.leftPersonnelList.length;i++){
                                leftTmpName+=_this.leftPersonnelList[i].personName;
                            }
                            //遍历右侧全部人员列表，删除当前法人已经选取的人员，仅显示可选的人员
                            for(var i=0;i<_this.rightPersonnelList.length;i++){
                                if(leftTmpName.indexOf(_this.rightPersonnelList[i].personname)==-1){
                                    _this.tmpRightPersonnelList.push(_this.rightPersonnelList[i])
                                }
                            }

                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            // 法人已经分配的人员选中时触发的方法
            handleLeftCheckedChange(value){
                var _this=this;
            },
            // 人员列表
            allPersonnelList(){
                var _this=this;
                $.ajax({
                    type: 'GET',
                    url: _this.metadata_service + "legalPerson/listEnabledUsers",
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            _this.rightPersonnelList = data.data;
                            // console.log("所有用户");
                            // console.log(_this.rightPersonnelList);
                        } else
                        // console.log(data.errorMessage);
                            _this.common.errorTip(data.errorMessage);
                    }
                });
            },
            //人员列表中选中时，触发的方法
            handleRightCheckedChange(value){
                var _this=this;
            },
            //  <<按钮  左移
            toLeftTransfer(){
                var _this=this;
                // 该法人已经选择的人员，不能重复选择
                // for(var i=0;i<_this.leftPersonnelList.length;i++){
                //     for(var j=0;j<_this.dSrightPersonnel.length;j++){
                //         if(_this.leftPersonnelList[i].personName==_this.dSrightPersonnel[j]){
                //             console.log("该人员已被选");
                //             _this.dSrightPersonnel=[];
                //             console.log("请重新选择");
                //         }
                //     }
                // }
                //待选人员列表中选中的人员(toLeft)
                for(var i=0;i<_this.dSrightPersonnel.length;i++){
                    _this.dSrightPersonnelNameArray.push({"personname":_this.dSrightPersonnel[i],"personName":_this.dSrightPersonnel[i]});
                }
                _this.dSrightPersonnel=_this.dSrightPersonnelNameArray;
                //取用户的id
                for(var i=0;i<_this.rightPersonnelList.length;i++){
                    for(var j=0;j<_this.dSrightPersonnel.length;j++){
                        if(_this.dSrightPersonnel[j].personName==_this.rightPersonnelList[i].personname){
                            _this.dSrightPersonnel[j].id=_this.rightPersonnelList[i].userId;
                        }
                    }
                }

                if(_this.legalPersonName=="" || _this.legalPersonName==null){
                    var err=_this.languageType=="zh"?'请选择法人':'Please select a legal person';
                    _this.common.errorTip(err);
                    _this.dSrightPersonnelNameArray=[];
                    _this.dSrightPersonnel=[];
                }else{
                    if(_this.dSrightPersonnel.length){
                        for(var i=0;i<_this.dSrightPersonnel.length;i++){
                            _this.leftPersonnelList.push(_this.dSrightPersonnel[i]);
                        }
                        //遍历待选人员选中的元素，删除_this.tmpRightPersonnelList里的元素
                        var rightTmpName="";
                        for(var i=0;i<_this.dSrightPersonnel.length;i++){
                            rightTmpName+=_this.dSrightPersonnel[i].personname;
                        }
                        var tmptmpRightPersonnelList=_this.tmpRightPersonnelList;    // tmptmpRightPersonnelList临时的变量
                        _this.tmpRightPersonnelList=[];     //临时清空待测人员列表的元素，删除左移的元素后，重新赋值
                        for(var i=0;i<tmptmpRightPersonnelList.length;i++){
                            if(rightTmpName.indexOf(tmptmpRightPersonnelList[i].personname)==-1){
                                _this.tmpRightPersonnelList.push(tmptmpRightPersonnelList[i]);
                            }
                        }

                        _this.dSrightPersonnelNameArray=[];
                        _this.dSrightPersonnel=[];

                    }else{
                        var err1=_this.languageType=="zh"?'暂无选中项':'Selected item';
                        _this.common.errorTip(err1);
                    }
                }

            },
            // >>按钮 右移
            toRightTransfer(){
                var _this=this;
                if(_this.dSleftPersonnel=="" || _this.dSleftPersonnel==null){
                    _this.common.errorTip("暂无选中项");
                    // console.log("暂时没有选中项");
                }else{
                    //法人下面的人员列表中选中的人员
                    for(var i=0;i<_this.dSleftPersonnel.length;i++){
                        _this.dSleftPersonnelNameArray.push({"personname":_this.dSleftPersonnel[i],"personName":_this.dSleftPersonnel[i]});
                    }
                    _this.dSleftPersonnel=_this.dSleftPersonnelNameArray;
                    //取用户的id
                    for(var i=0;i<_this.leftPersonnelList.length;i++){
                        for(var j=0;j<_this.dSleftPersonnel.length;j++){
                            if(_this.dSleftPersonnel[j].personName==_this.leftPersonnelList[i].personname){
                                _this.dSleftPersonnel[j].id=_this.leftPersonnelList[i].id;
                            }
                        }
                    }
                    // 点击>>按钮后，选中的元素右移，左侧不在显示选中的元素
                    var toRightName="";    //左侧定义临时变量
                    for(var i=0;i<_this.dSleftPersonnel.length;i++){
                        _this.tmpRightPersonnelList.push(_this.dSleftPersonnel[i]);
                        toRightName+=_this.dSleftPersonnel[i].personName;
                    }
                    var tmpLeftPersonnelListValue=_this.leftPersonnelList;
                    _this.leftPersonnelList=[];
                    for(var j=0;j<tmpLeftPersonnelListValue.length;j++){
                        if(toRightName.indexOf(tmpLeftPersonnelListValue[j].personName)==-1){
                            _this.leftPersonnelList.push(tmpLeftPersonnelListValue[j]);
                        }
                    }
                    _this.dSleftPersonnelNameArray=[];
                    _this.dSleftPersonnel=[];
                }
            },
            // 清除按钮
            clearCheckedValue(){
                var _this=this;
                _this.leftPersonnelList=[];
                _this.tmpRightPersonnelList=_this.rightPersonnelList;
            },
            // 提交结果
            submitResult(){
                var _this=this;
                var tmp = [{"id": _this.legalPersonId, "legalPersonName": _this.legalPersonName, "userList": _this.leftPersonnelList}];
                _this.submitRDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "/legalPerson/allotLegalPerson",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            var success=_this.languageType=="zh"?'提交成功！':'Submit successfully!';
                            _this.common.successTip(success);
                            _this.handleQuery(_this.pageIndex, _this.pageSize);   //查询结果重新显示
                            _this.showDistributiveLegalPersonFrom =false;
                            _this.dSrightPersonnel=[];
                            _this.dSrightPersonnelNameArray=[];


                            _this.legalPersonName="";
                            // _this.legalPersonId="";
                            _this.leftPersonnelList=[];
                            _this.dSleftPersonnel=[];
                            _this.dSleftPersonnelNameArray=[];

                        } else
                            _this.common.errorTip(data.errorMessage);
                        _this.submitRDisabled=false;
                    }
                });
            },
            //查询按钮点击事件
            handleQuery(pageIndex,pageSize){
                var _this = this;
                _this.loading=true;
                var tmp = {
                    personName: _this.queryDepartmentPersonForm.name,
                    userName: _this.queryDepartmentPersonForm.code,
                    enabled: _this.queryDepartmentPersonForm.enabled,
                    pageIndex: pageIndex,
                    pageSize: pageSize
                };
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "legalPerson/staff/search",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.loading=false;
                            _this.tableData = data.data.dataList;
                            _this.isPaging = true;
                            _this.totalPage = data.data.totalPage;
                            _this.totalNumber = data.data.totalNumber;
                        } else{
                            _this.common.errorTip(data.errorMessage);
                        }                            
                        _this.selectDisabled=false;
                    }
                });
            },
            // 分页
            handleSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                var _this = this;
                _this.pageSize=val;
                _this.handleQuery(_this.pageIndex, _this.pageSize);
            },
            //点击页码分页查询点击事件
            handleCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                var _this = this;
                _this.pageIndex=val;
                _this.handleQuery(_this.pageIndex, _this.pageSize);
            },
            //启用按钮点击事件
            handleEnable(index, row){
                var _this = this;
                _this.updatestatus(row.userId, true);
            },
            //禁用按钮点击事件
            handleDisable(index, row){
                var _this = this;
                _this.updatestatus(row.userId, false);
            },
            //修改按钮状态
            updatestatus(id, status) {
                var _this = this;
                var tmp = {userId: id, enabled: status};
                _this.statusDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "legalPerson/updateStaffStatus",
                    cache: false,
                    data: JSON.stringify(tmp),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            var success=_this.languageType=="zh"?'操作成功！':'Successful operation!';
                            _this.common.successTip(success);
                            _this.handleQuery(_this.pageIndex, _this.pageSize);
                        } else{
                            _this.common.errorTip(data.errorMessage);
                        }                            
                        _this.statusDisabled=false;
                    }
                });
            },
            //修改点击事件
            handleEdit(index, row){
                var _this = this;
                _this.form = Vue.util.extend(_this.form, row);
                _this.form.legalPersonIds = [];
                if (row.legalPersons && row.legalPersons.length) {
                    for (var i = 0; i < row.legalPersons.length; i++) {
                        _this.form.legalPersonIds.push(row.legalPersons[i].legalPersonId);
                    }
                }
                _this.dialogFormVisible = true;
                var parameters = {
                    pageIndex: 1,
                    pageSize: 1000,
                    enabled: true
                };
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "legalPerson/search",
                    cache: false,
                    data: JSON.stringify(parameters),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.legalPersonList = data.data.dataList;
                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });

                if (row.status == false) {
                    _this.allStatus = 'disable';
                } else {
                    _this.allStatus = 'start';
                }
            },
            //查看法人历史点击事件
            searchHistory(index, row){
                var _this = this;
                _this.form = Vue.util.extend(_this.form, row);
                _this.form.legalPersonIds = [];
                if (row.legalPersons && row.legalPersons.length) {
                    for (var i = 0; i < row.legalPersons.length; i++) {
                        _this.form.legalPersonIds.push(row.legalPersons[i].legalPersonId);
                    }
                }
                _this.searchHistoryFormVisible = true;
                var parameters = {
                    id: row.userId,
                };
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "/legalPerson/LegalPersonHistory",
                    cache: false,
                    data: JSON.stringify(parameters),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.legalPersonList = data.data;
                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });

                if (row.status == false) {
                    _this.allStatus = 'disable';
                } else {
                    _this.allStatus = 'start';
                }
            },
            //修改里面的保存按钮点击事件
            saveLegalPersonStaff() {
                var _this = this;
                _this.$refs["form"].validate((valid) => {
                    if (valid) {
                        if (_this.form.allStatus == "start") {
                            _this.form.status = true;
                        } else {
                            _this.form.status = false;
                        }
                        var tmp = {
                            id: _this.form.userId,
                            legalPersonIdList: _this.form.legalPersonIds,
                        }; 
                        _this.saveLDisabled=true;
                        $.ajax({
                            type: 'POST',
                            url: _this.metadata_service + "legalPerson/allotForSingle",
                            cache: false,
                            data: JSON.stringify(tmp),
                            dataType: 'JSON',
                            contentType: "application/json;charset=utf-8",
                            success: function (data) {
                                if (data.success) {
                                    var success=_this.languageType=="zh"?'保存成功！':'Save successfully!';
                                    _this.common.successTip(success);
                                    _this.handleQuery(_this.pageIndex, _this.pageSize);
                                    _this.dialogFormVisible = false;
                                } else{
                                    _this.common.errorTip(data.errorMessage);
                                }   
                                _this.saveLDisabled=false;                                 
                            }
                        });
                    } else {
                        var  err=_this.common.formErrorInfo();
                        _this.common.errorTip(err);
                        return false;
                    }
                });
            },

            //重置密码点击事件
            resetPassword(index, row){
                var _this = this;

                _this.dialogFormVisible = false;
                _this.resetPasswordFormVisible = true;
                _this.resetPasswordForm=row;

                _this.resetPasswordForm.userId = row.userId;
                _this.resetPasswordForm.username = row.username;
                _this.resetPasswordForm.personname = row.personname;
                _this.resetPasswordForm.legalPersons=row.legalPersons;
                _this.resetPasswordForm.password = "";
                _this.resetPasswordForm.checkPass = "";
                var parameters = {
                    pageIndex: 1,
                    pageSize: 1000,
                    enabled: true
                };
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service + "legalPerson/search",
                    cache: false,
                    data: JSON.stringify(parameters),
                    dataType: 'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        if (data.success) {
                            _this.legalPersonList = data.data.dataList;
                        } else
                            _this.common.errorTip(data.errorMessage);
                    }
                });

            },
            //重置密码保存点击事件
            handleSaveResetPassword(formName) {
                var _this = this;
                _this.$refs[formName].validate((valid) => {
                    if (valid) {
                        var tmp = {
                            id: _this.resetPasswordForm.userId,
                            password: _this.resetPasswordForm.password,
                        };
                        _this.saveRPDisabled=true;
                        $.ajax({
                            type: 'POST',
                            url: _this.metadata_service + "/legalPerson/resetPassword",
                            cache: false,
                            data: JSON.stringify(tmp),
                            dataType: 'JSON',
                            contentType: "application/json;charset=utf-8",
                            success: function (data) {
                                if (data.success) {
                                    var success=_this.languageType=="zh"?'密码重置成功！':'Password reset succeeded!';
                                    _this.common.successTip(success);
                                    _this.handleQuery(_this.pageIndex, _this.pageSize);
                                    _this.resetPasswordFormVisible=false
                                } else{
                                    _this.common.errorTip(data.errorMessage);
                                }
                                _this.saveRPDisabled=false;   
                            }
                        });
                    } else {
                        var  err=_this.common.formErrorInfo();
                        _this.common.errorTip(err);
                        return false;
                    }
                });
            }
        }
    }
</script>